package com.example.booksales.controller;

import com.example.booksales.domain.User;
import com.example.booksales.service.impl.UserService;
import com.example.booksales.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理(0613胡宇星)")
public class UserController {
    @Autowired
    UserService service;
    @GetMapping("/getUserListAll")
    @ApiOperation(value = "获取全部用户信息列表(0613胡宇星)")
    public AjaxResult getUserListAll() {
        System.out.println(service.selectAll());
        return AjaxResult.success(service.selectAll());
    };
    @GetMapping("/getUserById")
    @ApiOperation(value = "根据id查询用户信息(0613胡宇星)")
    public AjaxResult getUserById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResult.success(service.selectById(id));
    }
    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户(0613胡宇星)")
    public AjaxResult addUser(@RequestBody User user) {
        return AjaxResult.success(service.SaveUser(user));
    }
    @PutMapping("/UpdateUser")
    @ApiOperation(value = "修改用户信息(0613胡宇星)")
    public AjaxResult UpdateUser(@RequestBody User user){
        return AjaxResult.success(service.UpdateUser(user));
    }
    @DeleteMapping("/DeleteUser")
    @ApiOperation(value = "删除用户(0613胡宇星)")
    public AjaxResult DeleteUser(int id) {
        return AjaxResult.success(service.DeleteUser(id));
    }
    @GetMapping("/UserLogin")
    @ApiOperation(value = "用户登录(0613胡宇星)")
    public AjaxResult UserLogin(User user) {
        return AjaxResult.success(service.checkUser(user));
    }
}
